﻿package com.jstzrmyy.mams;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.google.zxing.client.android.CaptureActivity;

public class MainActivity extends Activity {
	
	// 使用ZXing扫描
	private static final int ZXING_SCAN = 3;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
    @Override  
    public boolean onOptionsItemSelected(MenuItem item) {  
        switch (item.getItemId()) {  
        case R.id.menu_scan:
        	startScan(); 
            return true;
        	//break;   
        case R.id.action_settings:   
            break;  
        }  
        return super.onOptionsItemSelected(item);  
    } 
    
	@Override      
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {      
	    super.onActivityResult(requestCode, resultCode, data);    
	    // ZXING扫描
	    if(requestCode == ZXING_SCAN){  
	        if (resultCode == RESULT_OK) {   
	            String zxingresult = data.getStringExtra("SCAN_RESULT");  
	            Toast.makeText(this, zxingresult, Toast.LENGTH_SHORT).show();  
	        } else { 
	        
	        }  
	    }  
	}
    
    private void startScan() {
		Intent intent = new Intent();
		intent.setClass(MainActivity.this, CaptureActivity.class);   
		startActivityForResult(intent, ZXING_SCAN);      	
    }

}
